package com.alibaba.citrus.cr.platform.enhance.facade.service;

import com.alibaba.citrus.cr.common.annotation.FacadeInvoker;
import com.alibaba.citrus.cr.platform.enhance.functions.organization.OrganizationEntity;
import com.alibaba.lattice2.epoch.sdk.model.Result;

import com.epoch.app.crplatformenhance.api.organizationwrite.service.OrganizationWriteService;
import com.epoch.app.crplatformenhance.dto.request.OperateOrganizationRelationRequest;
import com.epoch.app.crplatformenhance.sdo.OrganizationRelationSDO;
import com.epoch.app.crplatformenhance.sdo.OrganizationSDO;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2021/9/3 12:26
 */
@Primary
@Service
public class OrganizationWriteServiceImpl implements OrganizationWriteService {

    @Override
    @FacadeInvoker
    public Result<String> createOrganization(OrganizationSDO request) {
        OrganizationEntity organizationEntity = OrganizationEntity.of(request,null);
        return organizationEntity.doCreate();
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> editOrganization(OrganizationSDO request) {
        OrganizationEntity organizationEntity = OrganizationEntity.of(request,null);
        return organizationEntity.doEdit();
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> addOrganizationRelation(OrganizationRelationSDO request) {
        OrganizationEntity organizationEntity = OrganizationEntity.of(null, request);
        return Result.success(organizationEntity.doCreateOrganizationRelation());
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> enableOrganizationRelation(OperateOrganizationRelationRequest request) {
        OrganizationRelationSDO organizationRelationSDO = new OrganizationRelationSDO();
        organizationRelationSDO.setId(request.getId());
        organizationRelationSDO.setVersion(request.getVersion());
        organizationRelationSDO.setCreator(request.getOperatorId());
        OrganizationEntity organizationEntity = OrganizationEntity.of(null, organizationRelationSDO);
        return Result.success(organizationEntity.doEnableOrganizationRelation());
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> disableOrganizationRelation(OperateOrganizationRelationRequest request) {
        OrganizationRelationSDO organizationRelationSDO = new OrganizationRelationSDO();
        organizationRelationSDO.setId(request.getId());
        organizationRelationSDO.setVersion(request.getVersion());
        organizationRelationSDO.setCreator(request.getOperatorId());
        OrganizationEntity organizationEntity = OrganizationEntity.of(null, organizationRelationSDO);
        return Result.success(organizationEntity.doDisableOrganizationRelation());
    }

}
